package org.oschina.api.manage.menu.dao;

import java.util.List;
import org.oschina.Constants;
import org.oschina.api.BaseDAO;
import org.oschina.api.manage.menu.vo.ManageMenuVo;
import org.springframework.stereotype.Repository;

@Repository
public class ManageMenuDAO extends BaseDAO {

	private final String findVo[]={"id","`name`","icon","path","parent","main","`index`"};
	
	/**
	 * 根据角色返回
	 * @param role
	 * @return
	 */
	public List<ManageMenuVo> findVoByRole(int role)
	{
		return getQueryHelper().query_cache(findVo, new String[]{"module IN (SELECT ml.id FROM "+Constants.DB_MODULE+" ml WHERE ml.id IN (SELECT ur.module FROM "+Constants.DB_USER_ROLE+" ur WHERE ur.role=?))"},
				new String[]{"ORDER BY `index`"}, new Object[]{role}, ManageMenuVo.class, -1, -1);
	}
}